//package com.mall.gateway.config;
//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.cors.CorsConfiguration;
//import org.springframework.web.cors.reactive.CorsWebFilter;
//import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
//
//@Configuration
//public class CorsConfig {
////    @Bean
////    public WebMvcConfigurer corsConfigurer() {
////
////        return new WebMvcConfigurer() {
////            @Override
////            public void addCorsMappings(CorsRegistry registry) {
////                registry.addMapping("/**")
////                        .allowedOrigins("http://localhost:3000") // 允许跨域访问的源站点
////                        .allowCredentials(true) // 允许发送跨域请求时携带cookie或其他凭据信息
////                        .allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的请求方法
////                        .allowedHeaders("*") // 允许的请求头
////                        .exposedHeaders(HttpHeaders.SET_COOKIE); // 允许访问响应头中的Set-Cookie字段
////            }
////        };
////    }
//
//    @Bean
//    public CorsWebFilter corsWebFilter(){
//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
//        CorsConfiguration corsConfiguration = new CorsConfiguration();
//
//        //1、配置跨域
//        corsConfiguration.addAllowedHeader("*");
//        corsConfiguration.addAllowedMethod("*");
////        corsConfiguration.addAllowedOrigin("*");
//        corsConfiguration.addAllowedOriginPattern("*");
//        corsConfiguration.setAllowCredentials(true);
//
//        source.registerCorsConfiguration("/**",corsConfiguration);
//        return new CorsWebFilter(source);
//    }
//}
